package top.superflow.db.orientdb

import com.orientechnologies.orient.core.db.`object`.ODatabaseObject
import top.superflow.db.api.DBConnection
import top.superflow.log.Loggable
import top.superflow.verify.Ensure

class OrientConnection (realConnection : ODatabaseObject)
                                            extends DBConnection
                                            with Ensure
                                            with Loggable
{
  notNull(realConnection, "The real connection can't be null.")
  
  private val currentConnection = realConnection
  private val metadata = new OrientMetadata(this.currentConnection.getMetadata)

  def save: Unit = {
    
  }
  
  def command : Unit = {
    
  }
  
  
  /**
   * Class/Table operation
   */
  def create[T](entityClass : Class[T]): Any = {
    notNull(entityClass, "The class of the entity should not be null.")
    
    if(this.metadata.getSchema.existsClass(entityClass)){
      logger.warn("The entity has already existed.")
      this.metadata.getSchema.getDBEntity(entityClass)
      return;
    }
    this.currentConnection.getEntityManager.registerEntityClass(entityClass)
    
  }
  
//  private def addFields(fieldMetas : List[DBField], tableObject : DBEntity){
//    notNull(tableObject)
//
//    for(field <- fieldMetas){
//      tableObject.addField(field)
//    }
//  }
//
//  private def addIndexes(indexes : List[DBIndex], tableObject : DBEntity) = {
//    notNull(tableObject)
//
//    for(index <- indexes){
//      tableObject.createIndex(index)
//    }
//  }
//
//  private def refreshIndex(){
//
//  }
  
  
  
  
  def begin: Unit = ???
  def commit: Unit = ???
  def rollback : Unit = ???
  def getTransaction: Unit = ???
  
  def close: Unit = ???
  
  
  def drop: Unit = ???
  
  def getName: Unit = ???
  def getSize: Unit = ???
  def getStatus: Unit = ???
  def getMetadata : OrientMetadata = {
    this.metadata
  }
  
  def getUrl: Unit = ???
  def getUser: Unit = ???
  def load: Unit = ???
  def release: Unit = ???
  def reload: Unit = ???
  

}
